package com.smartleanx.module.hrm.controller.admin.salary;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageInfo;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.security.core.util.SecurityFrameworkUtils;
import com.smartleanx.framework.tenant.core.aop.TenantIgnore;
import com.smartleanx.module.hrm.controller.admin.dingDing.bo.DingAttendanceConfirmationBo;
import com.smartleanx.module.hrm.controller.admin.employee.vo.EmployeeImportRespVO;
import com.smartleanx.module.hrm.dal.dataobject.salary.HrmSalaryFixed;
import com.smartleanx.module.hrm.dal.dataobject.salary.HrmSalaryPlan;
import com.smartleanx.module.hrm.dal.dataobject.salary.HrmSalaryTaxationRuleTenant;
import com.smartleanx.module.hrm.dal.dataobject.salary.HrmSalaryTemplate;
import com.smartleanx.module.hrm.dal.dataobject.salary.bo.HrmSalaryPlanInsertBo;
import com.smartleanx.module.hrm.dal.dataobject.salary.vo.*;
import com.smartleanx.module.hrm.service.salary.HrmSalaryFixedService;
import com.smartleanx.module.hrm.service.salary.HrmSalaryRecordService;
import com.smartleanx.module.hrm.service.salary.HrmSalaryTableConfigService;
import com.smartleanx.module.hrm.service.salary.HrmSalaryTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.stream.Collectors;

@Tag(name = "管理后台 - 薪资 ")
@RestController
@RequestMapping("/hrm/salary")
public class SalaryController {

    @Autowired
    private HrmSalaryTableConfigService hrmSalaryTableConfigService;

    @Autowired
    private HrmSalaryFixedService salaryFixedService;

    @Autowired
    private HrmSalaryTemplateService salaryTemplateService;

    @Autowired
    private HrmSalaryRecordService salaryRecordService;


    @GetMapping("/postLevelBySelect")
    public CommonResult<Object> postLevelBySelect() {
        return CommonResult.success(salaryRecordService.postLevelBySelect());
    }



    @GetMapping("/selectConfigList")
    public CommonResult<Object> selectConfigList(@RequestParam("type") Integer type) {
        return CommonResult.success(hrmSalaryTableConfigService.selectList(type));
    }


    @GetMapping("/selectListConfigInfo")
    public CommonResult<Object> selectListConfigInfo(@RequestParam("type") Integer type) {
        return CommonResult.success(hrmSalaryTableConfigService.selectListInfo(type));
    }

    @PostMapping("/insertOrUpdateConfig")
    public CommonResult<Object> insertOrUpdateConfig(@RequestBody List<HrmSalaryTableConfigVo> hrmSalaryTableConfigVos) {
        return CommonResult.success(hrmSalaryTableConfigService.insertOrUpdate(hrmSalaryTableConfigVos));
    }


    @GetMapping("/init")
    @PermitAll
    @TenantIgnore
    public CommonResult<Object> init(@RequestParam("tenantId") Integer tenantId) {
        return CommonResult.success(hrmSalaryTableConfigService.init(tenantId));
    }


    /**
     * 考勤导入字段设置 ==============================================================================================================================
     */
    @GetMapping("/selectSystemColumnListConfigInfo")
    public CommonResult<Object> selectSystemColumnListConfigInfo(@RequestParam("type") Integer type) {
        return CommonResult.success(hrmSalaryTableConfigService.selectColumnListInfo(type));
    }


    @PostMapping("/columnInsertOrUpdate")
    public CommonResult<Object> columnInsertOrUpdate(@RequestBody List<SystemColumnTenantVo> systemColumnTenantVos) {
        return CommonResult.success(hrmSalaryTableConfigService.columnInsertOrUpdate(systemColumnTenantVos));
    }


    /**
     * 计薪设置
     *
     * @param type
     * @return
     */
    @GetMapping("/salarySettingSaveOrUpdate")
    public CommonResult<Object> salarySettingSaveOrUpdate(@RequestParam("type") Integer type) {
        hrmSalaryTableConfigService.salarySettingSaveOrUpdate(type);
        return CommonResult.success("操作成功");
    }

    /**
     * 计薪设置
     *
     * @return
     */
    @GetMapping("/selectSetting")
    public CommonResult<Object> selectSetting() {
        Integer i = hrmSalaryTableConfigService.selectSetting();
        return CommonResult.success(i);
    }


    /**
     * 计税规则设置列表
     */
    @GetMapping("/selectTaxationRuleList")
    public CommonResult<Object> selectTaxationRuleList(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<HrmSalaryTaxationRuleVo> hrmSalaryTaxationRuleVoPageInfo = hrmSalaryTableConfigService.selectTaxationRuleList(pageNum, pageSize);
        return CommonResult.success(hrmSalaryTaxationRuleVoPageInfo);
    }


    /**
     * 计税规则设置新增或修改
     */
    @PostMapping("/InsertOrUpdateTaxationRule")
    public CommonResult<Object> InsertOrUpdateTaxationRule(@RequestBody HrmSalaryTaxationRuleTenant HrmSalaryTaxationRuleTenant) {
        hrmSalaryTableConfigService.insertOrUpdateTaxationRule(HrmSalaryTaxationRuleTenant);
        return CommonResult.success("操作成功");
    }


    /**
     * 计税规则下拉
     */
    @GetMapping("/taxationRuleBySelect")
    public CommonResult<Object> taxationRuleBySelect() {
        List<JSONObject> jsonObjectList = hrmSalaryTableConfigService.taxationRuleBySelect();
        return CommonResult.success(jsonObjectList);
    }

    /**
     * 计税规则编辑回显
     *
     * @param id
     * @return
     */
    @GetMapping("/selectTaxationRuleById")
    public CommonResult<Object> selectTaxationRuleById(@RequestParam("id") Integer id) {
        HrmSalaryTaxationRuleTenant HrmSalaryTaxationRuleTenant = hrmSalaryTableConfigService.selectTaxationRuleById(id);
        return CommonResult.success(HrmSalaryTaxationRuleTenant);
    }

    /**
     * 薪资组新增
     */
    @PostMapping("/insertSalaryPlan")
    public CommonResult<Object> insertSalaryPlan(@RequestBody HrmSalaryPlanInsertBo hrmSalaryPlanInsertBo) {
        Integer i = hrmSalaryTableConfigService.insertSalaryPlan(hrmSalaryPlanInsertBo);
        return CommonResult.success(i);
    }

    /**
     * 薪资组编辑
     */
    @PostMapping("/updateSalaryPlan")
    public CommonResult<Object> updateSalaryPlan(@RequestBody HrmSalaryPlanInsertBo hrmSalaryPlanInsertBo) {
        Integer i = hrmSalaryTableConfigService.updateSalaryPlan(hrmSalaryPlanInsertBo);
        return CommonResult.success(i);
    }

    /**
     * 薪资组列表
     */
    @GetMapping("/salaryPlanList")
    public CommonResult<Object> salaryPlanList(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<HrmSalaryPlanInsertVo> hrmSalaryPlanInsertVoPageInfo = hrmSalaryTableConfigService.salaryPlanList(pageNum, pageSize);
        return CommonResult.success(hrmSalaryPlanInsertVoPageInfo);
    }

    /**
     * 薪资组回显
     */
    @GetMapping("/selectSalaryPlanById")
    public CommonResult<Object> selectSalaryPlanById(@RequestParam("id") Integer id) {
        HrmSalaryPlan hrmSalaryPlanInsertVo = hrmSalaryTableConfigService.selectSalaryPlanById(id);
        return CommonResult.success(hrmSalaryPlanInsertVo);
    }


    /**
     * 删除薪资组
     */
    @GetMapping("/deletedSalaryPlan")
    public CommonResult<Object> deletedSalaryPlan(@RequestParam("id") Integer id) {
        Integer deleted = hrmSalaryTableConfigService.deleted(id);
        return CommonResult.success("操作成功");
    }

    /**
     * 员工薪资档案
     */

    @GetMapping("/selectFixedList")
    public CommonResult<Object> selectFixedList(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, @RequestParam(value = "postName", required = false) Integer postName, @RequestParam(value = "postLevelId", required = false) Integer postLevelId, @RequestParam(value = "employeeFrom", required = false) Integer employeeFrom, @RequestParam(value = "employeeState", required = false) Integer employeeState, @RequestParam(value = "employeeResignation", required = false) Integer employeeResignation, @RequestParam(value = "employeeName", required = false) String employeeName, @RequestParam(value = "deptName", required = false) String deptName, @RequestParam(value = "employeeNo", required = false) String employeeNo,@RequestParam(value = "employeeIds",required = false) List<Integer> employeeIds) {
        PageInfo<FixedEmployeeVo> fixedEmployeeVoPageInfo = salaryFixedService.selectFixedList(pageNum, pageSize, postName, postLevelId, employeeFrom, employeeState, employeeResignation, employeeName, deptName, employeeNo,employeeIds);
        return CommonResult.success(fixedEmployeeVoPageInfo);
    }


    /**
     * 员工薪资档案修改
     *
     * @param hrmSalaryFixed
     * @return
     */
    @PostMapping("/updateEmployeeFixed")
    public CommonResult<Object> updateEmployeeFixed(@RequestBody HrmSalaryFixed hrmSalaryFixed) {
        salaryFixedService.updateEmployeeFixed(hrmSalaryFixed);
        return CommonResult.success("操作成功");
    }


    /**
     * 员工薪资档案调薪回显
     *
     * @param employeeId
     * @return
     */
    @GetMapping("/getEmployeeFixedById")
    public CommonResult<Object> getEmployeeFixedById(@RequestParam("employeeId") Integer employeeId) {
        FixedEmployeeVo employeeFixedById = salaryFixedService.getEmployeeFixedById(employeeId);
        return CommonResult.success(employeeFixedById);
    }



    /**
     * 调薪记录列表
     *
     * @param employeeId
     * @return
     */
    @GetMapping("/selectEmployeeFixedList")
    public CommonResult<Object> selectEmployeeFixedList(@RequestParam("employeeId") Integer employeeId) {
        List<HrmSalaryFixed> hrmSalaryFixeds = salaryFixedService.selectEmployeeFixedList(employeeId);
        return CommonResult.success(hrmSalaryFixeds);
    }

    /**
     * 调薪记录详情
     */
    @GetMapping("/getEmployeeFixedInfoById")
    public CommonResult<Object> getEmployeeFixedInfoById(@RequestParam("id") Integer id) {
        return CommonResult.success(salaryFixedService.getEmployeeFixedInfoById(id));
    }

    /**
     * 调薪记录详情
     */
    @GetMapping("/getEmployeeFixedInfoUpdateById")
    public CommonResult<Object> getEmployeeFixedInfoUpdateById(@RequestParam("id") Integer id) {
        return CommonResult.success(salaryFixedService.getEmployeeFixedInfoUpdateById(id));
    }


    /**
     * 调薪记录编辑
     */
    @PostMapping("/updateEmployeeFixedInfoById")
    public CommonResult<Object> updateEmployeeFixedInfoById(@RequestBody HrmSalaryFixed hrmSalaryFixed) {
        salaryFixedService.updateEmployeeFixedInfoById(hrmSalaryFixed);
        return CommonResult.success("操作成功");
    }


    /**
     * 调薪记录删除
     */
    @GetMapping("/deletedEmployeeFixedInfoById")
    public CommonResult<Object> deletedEmployeeFixedInfoById(@RequestParam("id") Integer id) {
        salaryFixedService.deletedEmployeeFixedInfoById(id);
        return CommonResult.success("操作成功");
    }


    /**
     *
     */
    @GetMapping("/selectByEmployeeInfo")
    public CommonResult<Object> selectByEmployeeInfo(@RequestParam("employeeId") Integer employeeId) {
        return CommonResult.success(salaryFixedService.selectByEmployeeInfo(employeeId));
    }


    /**
     * 员工薪资档案定薪
     *
     * @param hrmSalaryFixed
     * @return
     */
    @PostMapping("/insertEmployeeFixedInfo")
    public CommonResult<Object> insertEmployeeFixedInfo(@RequestBody HrmSalaryFixed hrmSalaryFixed) {
        salaryFixedService.insertEmployeeFixedInfo(hrmSalaryFixed);
        return CommonResult.success("操作成功");
    }


    @PostMapping("/updateEmployeeFixedInfo")
    public CommonResult<Object> updateEmployeeFixedInfo(@RequestBody HrmSalaryFixed hrmSalaryFixed) {
        salaryFixedService.updateEmployeeFixedInfo(hrmSalaryFixed);
        return CommonResult.success("操作成功");
    }


//================================================== 定薪模版======================================================================//

    @GetMapping("/firstSelectTableList")
    public CommonResult<Object> firstSelectTableList() {
        List<HrmSalaryTableConfigVo> salaryTableConfigVoList = salaryTemplateService.firstSelectTableList();
        return CommonResult.success(salaryTableConfigVoList);
    }


    @GetMapping("/findSalaryTemplateAll")
    public CommonResult<Object> findSalaryTemplateAll() {
        List<HrmSalaryTemplate> salaryTemplateAll = salaryTemplateService.findSalaryTemplateAll();
        return CommonResult.success(salaryTemplateAll);
    }


    @GetMapping("/selectSalaryTemplateById")
    public CommonResult<Object> selectSalaryTemplateById(@RequestParam("id") Long id) {
        HrmSalaryTemplate salaryTemplate = salaryTemplateService.selectSalaryTemplateById(id);
        return CommonResult.success(salaryTemplate);
    }

    @PostMapping("/insertSalaryTemplate")
    public CommonResult<Object> insertSalaryTemplate(@RequestBody HrmSalaryTemplate hrmSalaryTemplate) {
        salaryTemplateService.insertSalaryTemplate(hrmSalaryTemplate);
        return CommonResult.success("操作成功");
    }

    @PostMapping("/updateSalaryTemplate")
    public CommonResult<Object> updateSalaryTemplate(@RequestBody HrmSalaryTemplate hrmSalaryTemplate) {
        salaryTemplateService.updateSalaryTemplate(hrmSalaryTemplate);
        return CommonResult.success("操作成功");
    }

    @GetMapping("/deleteSalaryTemplateById")
    public CommonResult<Object> deleteSalaryTemplateById(@RequestParam("id") Long id) {
        salaryTemplateService.deleteSalaryTemplateById(id);
        return CommonResult.success("操作成功");
    }


    @PostMapping("/generateSalaryRecord")
    public CommonResult<Object> generateSalaryRecord(@RequestBody JSONObject param) {
        param.getInteger("isAccumulation");
        param.getInteger("isProgramme");
        List<Integer> employeeIds = param.getList("employeeIds", Integer.class);
        String string = param.getString("date");
        Integer type = param.getInteger("type");

        Integer hsType = param.getInteger("hsType");

        salaryRecordService.generateSalaryRecordNew(type, employeeIds, string,hsType);
        return CommonResult.success("生成成功");
    }

    @PostMapping("/selectRecordList")
    public CommonResult<Object> selectRecordList(@RequestBody JSONObject param) {

        return CommonResult.success(salaryRecordService.selectRecordList(param));
    }


    @PostMapping("/selectRecordListInfo")
    public CommonResult<Object> selectRecordListInfo(@RequestBody JSONObject param) {
        JSONObject jsonObjectPageInfo = salaryRecordService.selectRecordListInfo(param);
        return CommonResult.success(jsonObjectPageInfo);
    }

    @PostMapping("/updateRecordInfo")
    public CommonResult<Object> updateRecordInfo(@RequestBody JSONObject jsonObject) {
        salaryRecordService.updateRecordInfo(jsonObject);
        return CommonResult.success("操作成功");
    }


    @PostMapping("/selectRecordUpdateListInfo")
    public CommonResult<Object> selectRecordUpdateListInfo(@RequestBody JSONObject param) {
        JSONObject jsonObjectPageInfo = salaryRecordService.selectRecordUpdateListInfo(param);
        return CommonResult.success(jsonObjectPageInfo);
    }

    @PostMapping("/selectRecordUpdateListInfoBYDA")
    public CommonResult<Object> selectRecordUpdateListInfoBYDA(@RequestBody JSONObject param) {
        JSONObject jsonObjectPageInfo = salaryRecordService.selectRecordUpdateListInfoBYDA(param);
        return CommonResult.success(jsonObjectPageInfo);
    }


    @GetMapping("/selectConfirmTable")
    public CommonResult<Object> selectConfirmTable(@RequestParam("id") Integer id) {
        return CommonResult.success(salaryRecordService.selectConfirmTable(id));
    }

    @PostMapping("/updateConfirm")
    public CommonResult<Object> updateConfirm(@RequestBody JSONObject date) {

        return CommonResult.success(salaryRecordService.updateConfirm(date));
    }

    @PostMapping("/selectConfirmRecordListInfo")
    public CommonResult<Object> selectConfirmRecordListInfo(@RequestBody JSONObject param) {

        return CommonResult.success(salaryRecordService.selectConfirmRecordListInfo(param));
    }


    @PostMapping("/selectConfirmInfoList")
    public CommonResult<JSONObject> selectConfirmInfoList(@RequestBody JSONObject param) {
        return CommonResult.success(salaryRecordService.selectConfirmInfoList(param));
    }


    @GetMapping("/selectConfirmRecordListInfo")
    public CommonResult<Object> selectConfirmRecordListInfo(@RequestParam("date") String date) {

        JSONObject param = new JSONObject();
        param.put("date", date);
        return CommonResult.success(salaryRecordService.selectConfirmRecordListInfo(param));
    }

    @PostMapping("/withdraw")
    public CommonResult<Object> withdraw(@RequestBody JSONObject param) {
        Integer ids = param.getInteger("ids");
        return CommonResult.success(salaryRecordService.withdraw(ids));
    }

    @PostMapping("/sendConfirm")
    public CommonResult<Object> sendConfirm(@RequestBody JSONObject param) {
        Integer ids = param.getInteger("ids");
        return CommonResult.success(salaryRecordService.sendConfirm(ids));
    }


    @GetMapping("/selectByConfirmPage")
    public CommonResult<Object> selectByConfirmPage(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        Long loginId = SecurityFrameworkUtils.getLoginUserId();

        return CommonResult.success(salaryRecordService.selectByConfirmPage(loginId.intValue(), pageNum, pageSize));


    }

    @GetMapping("/allSendConfirm")
    public CommonResult<Object> allSendConfirm(@RequestParam("recordId") Integer recordId) {
        return CommonResult.success(salaryRecordService.allSendConfirm(recordId));
    }

    @GetMapping("/allWithdraw")
    public CommonResult<Object> allWithdraw(@RequestParam("recordId") Integer recordId) {
        return CommonResult.success(salaryRecordService.allWithdraw(recordId));
    }

    @GetMapping("/selectEmployeeConfirmInfo")
    public CommonResult<Object> selectEmployeeConfirmInfo(@RequestParam("id") Integer id) {
        return CommonResult.success(salaryRecordService.selectEmployeeConfirmInfo(id));
    }

    @GetMapping("/historySalaryList")
    public CommonResult<Object> historySalaryList(@RequestParam("date") String date) {
        return CommonResult.success(salaryRecordService.historySalaryList(date));
    }

    @PostMapping("/historySalaryInfo")
    public CommonResult<Object> historySalaryInfo(@RequestBody JSONObject jsonObject) {
        JSONObject jsonObject1 = salaryRecordService.historySalaryInfo(jsonObject);
        return CommonResult.success(jsonObject1);
    }

    @GetMapping("/updateRemark")
    public CommonResult<Object> updateRemark(@RequestParam("remark") String remark, @RequestParam("id") Integer id) {
        return CommonResult.success(salaryRecordService.updateRemark(remark, id));
    }


    @GetMapping("/removeSalary")
    public CommonResult<Object> removeSalary(@RequestParam("recordId") Integer recordId) {
        return CommonResult.success(salaryRecordService.removeSalary(recordId));
    }


    @GetMapping("/selectList")
    public CommonResult<Object> selectList() {
        return CommonResult.success(salaryRecordService.selectList());
    }

    @GetMapping("/confirm")
    public CommonResult<Object> confirm(@RequestParam("id") Integer id, @RequestParam("status") Integer status, @RequestParam(value = "message", required = false) String message) {
        salaryRecordService.confirm(id, status, message);
        return CommonResult.success("操作成功");
    }

    @GetMapping("/checkStatus")
    public CommonResult<Object> checkStatus(@RequestParam("id") Integer id) {
        salaryRecordService.checkStatus(id);
        return CommonResult.success("操作成功");
    }

    @GetMapping("/selectNotDingUserEmployeeIdList")
    public CommonResult<Object> selectNotDingUserEmployeeIdList() {
        return CommonResult.success(salaryRecordService.selectNotDingUserEmployeeIdList());
    }

    @PostMapping("/selectNotSalaryEmployeeList")
    public CommonResult<Object> selectNotSalaryEmployeeList(@RequestBody JSONObject jsonObject) {
        List<Integer> employeeIds = jsonObject.getList("employeeIds", Integer.class);
        return CommonResult.success(salaryRecordService.selectNotSalaryEmployeeList(employeeIds));
    }


    @PostMapping("/selectByNotSalary")
    public CommonResult<Object> selectByNotSalary(@RequestBody JSONObject jsonObject) {
        List<Integer> employeeIds = jsonObject.getList("employeeIds", Integer.class);
        String month = jsonObject.getString("month");
        Integer isSystem = jsonObject.getInteger("isSystem");
        if (ObjectUtils.isEmpty(employeeIds)) {
            return null;
        }

        JSONObject jsonObject1 = salaryRecordService.selectByNotSalary(employeeIds, month,isSystem);
        System.err.println(jsonObject1);
        return CommonResult.success(jsonObject1);
    }


    @GetMapping("/selectByAttendanceErrorEmployeeCount")
    public CommonResult<Object> selectByAttendanceErrorEmployeeCount(@RequestParam("month") String month) {
        Integer count = salaryRecordService.selectByAttendanceErrorEmployeeCount(month + "-01 00:00:00", month + "-31 00:00:00");
        return CommonResult.success(count);
    }


    @GetMapping("/selectByAttendanceErrorEmployee")
    public CommonResult<Object> selectByAttendanceErrorEmployee(@RequestParam("month") String month) {
        List<JSONObject> jsonObjectList = salaryRecordService.selectByAttendanceErrorEmployee(month + "-01 00:00:00", month + "-31 00:00:00");
        return CommonResult.success(jsonObjectList);
    }

    @GetMapping("/selectYcDingSelect")
    @TenantIgnore
    public CommonResult<Object> selectYcDingSelect() {
        List<JSONObject> jsonObjectList = salaryRecordService.selectYcDingSelect();
        return CommonResult.success(jsonObjectList);
    }

    @GetMapping("/downloadTemp")
    @TenantIgnore
    public void downloadTemp(HttpServletResponse respons) {
        salaryTemplateService.downloadTemp(respons);
    }

    @PostMapping("/importTemp")
    public CommonResult<Object> importTemp(@RequestParam("columnIdList") String columnIdList,@RequestParam("date") String date
            ,@RequestParam("confirmationName") String confirmationName ,@RequestParam("content") String content,@RequestParam("xsType") Integer xsType
            ,@RequestParam("file") MultipartFile file) {
        DingAttendanceConfirmationBo confirmationBo = new DingAttendanceConfirmationBo();
        confirmationBo.setDate(date);
        List<String> strings = StrUtil.splitTrim( columnIdList,",");
        List<Integer> collect = strings.stream().map(Integer::parseInt).collect(Collectors.toList());
        confirmationBo.setColumnIdList(collect);
        confirmationBo.setConfirmationName(confirmationName);
        confirmationBo.setContent(content);
        confirmationBo.setXsType(xsType);
        EmployeeImportRespVO employeeImportRespVO = salaryTemplateService.importTemp(file, confirmationBo);
        if(employeeImportRespVO.getFailureNames().size() <= 0){
            return new CommonResult<>().setCode(0).setData(null).setMsg("操作成功");
        }
        return CommonResult.success(employeeImportRespVO);
    }

    @PostMapping("/verifyImportData")
    public CommonResult<Object> verifyImportData(@RequestParam("date") String date,@RequestParam("file") MultipartFile file) {
        DingAttendanceConfirmationBo confirmationBo = new DingAttendanceConfirmationBo();
        confirmationBo.setDate(date);
        EmployeeImportRespVO employeeImportRespVO = salaryTemplateService.verifyImportData(file, confirmationBo);
        if(employeeImportRespVO.getFailureNames().size() <= 0){
            return new CommonResult<>().setCode(0).setData(employeeImportRespVO.getFile()).setMsg("操作成功");
        }
        return CommonResult.success(employeeImportRespVO);
    }


    @GetMapping("/getColumn")
    @TenantIgnore
    public CommonResult<Object> getColumn() {
        return CommonResult.success(salaryTemplateService.getColumn());
    }

    @Operation(summary = "下载客户导入失败数据")
    @GetMapping("/importDownload")
    public void importDownload(HttpServletResponse response, String fileName,String filePath) {
        try {
//            String filePath = "C:\\Users\\a\\AppData\\Local\\Temp\\" + fileName;
//            String filePath = "/tmp/" + fileName;

            File tempFile = new File(filePath);
            try (FileInputStream fis = new FileInputStream(tempFile)) {
                byte[] buffer = new byte[fis.available()];
                int read = fis.read(buffer);
                //设置mime类型
                response.setContentType("application/octet-stream");
                //设置编码
                response.setCharacterEncoding("utf-8");
                //设置响应头信息 Content-disposition
                fileName = URLEncoder.encode(fileName, "UTF-8");
                response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
                OutputStream toClient = new BufferedOutputStream(response.getOutputStream());

                toClient.write(buffer);
                toClient.flush();
                toClient.close();
            }
        } catch (Exception e) {
//            log.error("文件导出下载报错message {}", e.getMessage());

        }
    }







//   计薪标准==================================================================================================================================
//    @PostMapping("/insertSalaryStandard")
//    public  CommonResult<Object> insertSalaryStandard(@RequestBody HrmSalaryStandard hrmSalaryStandard) {
//        hrmSalaryStandardService.insertSalaryStandard(hrmSalaryStandard);
//        return CommonResult.success("操作成功");
//    }
//    /**
//     * 计薪标准修改
//     */
//    @PostMapping("/updateSalaryStandard")
//    public  CommonResult<Object> updateSalaryStandard(@RequestBody HrmSalaryStandard hrmSalaryStandard) {
//        hrmSalaryStandardService.updateSalaryStandard(hrmSalaryStandard);
//        return CommonResult.success("操作成功");
//    }
//    /**
//     * 计薪标准列表
//     */
//    @GetMapping("/selectSalaryStandardByPage")
//    public  CommonResult<Object> selectSalaryStandardByPage(@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize) {
//        PageInfo<HrmSalaryStandard> hrmSalaryStandardPageInfo = hrmSalaryStandardService.selectSalaryStandardByPage(pageNum, pageSize);
//        return CommonResult.success(hrmSalaryStandardPageInfo);
//    }
//    /**
//     * 计薪标准下拉
//     */
//    @GetMapping("/salaryStandardBySelect")
//    public CommonResult<Object> salaryStandardBySelect(){
//        List<JSONObject> jsonObjects = hrmSalaryStandardService.salaryStandardBySelect();
//        return CommonResult.success(jsonObjects);
//    }
}
